﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using AForge.Imaging.Filters;

namespace WpfImageDuplicates
{
    /// <summary>
    /// Interaction logic for FilterView.xaml
    /// </summary>
    public partial class FilterView : UserControl
    {
        public event EventHandler WantRemoveFilter;
        public event EventHandler WantMoveLeft;
        public event EventHandler WantMoveRight;

        public static readonly DependencyProperty FilterViewModelProperty =
            DependencyProperty.Register( "FilterViewModel", typeof(FilterViewModel), typeof(FilterView), new PropertyMetadata(null, OnFilterViewModelPropertyChanged));

        public FilterViewModel FilterViewModel
        {
            get { return (FilterViewModel)GetValue(FilterViewModelProperty); }
            set { SetValue(FilterViewModelProperty, value); }
        }

        private static void OnFilterViewModelPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            FilterView source = d as FilterView;
            FilterViewModel v = e.NewValue as FilterViewModel;
            source.UpdateFilterViewModel(v);
        }

        private void UpdateFilterViewModel(FilterViewModel viewModel)
        {
            FilterViewModel = viewModel;
            this.DataContext = FilterViewModel;            
        }
        
        public FilterView()
        {
            InitializeComponent();
        }

        private void btnFilterSettings_Click(object sender, RoutedEventArgs e)
        {
            // HEREHERE
        }

        private void btnRemoveFilter_Click(object sender, RoutedEventArgs e)
        {
            if (WantRemoveFilter != null)
                WantRemoveFilter(this, EventArgs.Empty);
        }

        private void btnMoveLeft_Click(object sender, RoutedEventArgs e)
        {
            if (WantMoveLeft != null)
                WantMoveLeft(this, EventArgs.Empty);
        }

        private void btnMoveRight_Click(object sender, RoutedEventArgs e)
        {
            if (WantMoveRight != null)
                WantMoveRight(this, EventArgs.Empty);
        }
    }
}
